package logic

import (
	"context"
	"novel-start/models/mysql"

	"novel-start/novelrpc/internal/svc"
	"novel-start/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewNovelShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelShowLogic {
	return &NovelShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *NovelShowLogic) NovelShow(in *novelrpc.NovelShowRequest) (*novelrpc.NovelShowResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.User

	if err := user.FindUserById(mysql.DB, in.UserId); err != nil {
		return nil, err
	}

	var novel mysql.Novel

	show := novel.NovelShow(mysql.DB, in)

	return &novelrpc.NovelShowResponse{
		NovelId:   show.NovelId,
		Title:     show.Title,
		Type:      show.Type,
		NovelDesc: show.NovelDesc,
		NovelUrl:  show.NovelUrl,
		NovelNum:  show.NovelNum,
		NickName:  show.NickName,
		HeadImage: show.HeadImage,
	}, nil
}
